package com.doge.service.wx.catalog;

import com.doge.bean.pojo.category.Category;
import com.doge.bean.pojo.category.CategoryExample;
import com.doge.bean.vo.category.WxCategoryCurrentVo;
import com.doge.mapper.CategoryMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @program: doge
 * @description: 微信类目的服务
 * @author: Mr.Jiang
 * @create: 2021-12-02 11:33
 **/
@Service
public class WxCatalogServiceImpl implements WxCatalogService{
    @Autowired
    CategoryMapper categoryMapper;


    @Override
    public WxCategoryCurrentVo current(Integer id) {
        //查询当前类目
        Category category = categoryMapper.selectByPrimaryKey(id);
        //查询所有一级类目
        CategoryExample categoryExample = new CategoryExample();
        categoryExample.createCriteria().andPidEqualTo(0).andDeletedEqualTo(false);
        List<Category> categories = categoryMapper.selectByExample(categoryExample);
        //查询当前类目对应的所有二级类目
        CategoryExample categoryExample1 = new CategoryExample();
        categoryExample1.createCriteria().andPidEqualTo(category.getId()).andDeletedEqualTo(false);
        List<Category> categories1 = categoryMapper.selectByExample(categoryExample1);
        //构造结果
        WxCategoryCurrentVo wxCategoryCurrentVo = new WxCategoryCurrentVo();
        wxCategoryCurrentVo.setCurrentCategory(category);
        wxCategoryCurrentVo.setCategoryList(categories);
        wxCategoryCurrentVo.setCurrentSubCategory(categories1);
        return wxCategoryCurrentVo;
    }
}
